Repository navigation
Conversation
When an aliased import inside a deferred block (or one whose child has deferred nodes) is left as a raw import tag for the next pass, the parent's variables and macros that the imported template reads were not reconstructed, so the second pass saw them as undefined. Collect the words the imported template uses and reconstruct/defer them in front of the deferred import tag, as other deferred tags do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…edImport Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second pass used jinjava.newInterpreter(), whose config has the test base's legacy overrides, while the eager pass used its own. Build both from one config method that only differs in execution mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlpriElse
marked this pull request as ready for review
November 24, 2026 10:05
Contributor
Author
|
@jasmith-hs these are all my gifts for tonight sweet child, don't wanna burn all my Claude limits for these funzies but I've got another dozen unconfirmed bugs found |
…erred import
When an aliased import of a macro-defining template is deferred, the parent
macros the imported template reads are reconstructed in front of it. A
parent macro that uses caller(), called by the imported template with
{% call %}, failed to reconstruct: caller() couldn't be resolved, which is
a FATAL error, and the rebuilt macro lost its {{ caller() }}.
Like EagerCallTag, register a deferred placeholder caller macro in a
temporary scope while reconstructing, so caller() stays in the macro.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlpriElse
marked this pull request as draft
November 24, 2026 10:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Touches the same code as #1369, but fixes a different problem.
Context
EagerImportTaghandles{% import 'lib' as x %}in eager execution mode.When the import is inside a deferred block, such as
{% if deferred %}, andlibdefines a macro, the import can't be inlined. It's written back out as a raw{% import %}tag, which runs again when the output is fully rendered later.Problem
When the import was left as a raw tag, the parent template's state that
libreads, such as earliersettags and macros defined in the parent, wasn't kept in the eager output.On the second render pass,
libsaw those as undefined.EagerImportTagthrows away the child's render in this case and callsAliasedEagerImportingStrategy.handleDeferredTemplateFile. That method records only the path expression and the alias. Nothing recorded which parent variables the child reads, so they were never written out in front of the import.includeandfrom ... importaren't affected, because they inline the child's render instead of running it again.Broken Examples
What this PR Does
When the import of a macro-defining template is deferred,
EagerImportTagnow collects the candidate names (variables and macros) that the imported template's source references. When it returns the raw import, it writes the parent's variables and macros among those names in front of it, usingEagerReconstructionUtils.hydrateReconstructionFromContextBeforeDeferringand aDeferredToken.EagerPrintTagandEagerForTagalready use this pattern. Eager output for the first example:Only
EagerImportTagchanges; the importing strategies and shared eager utilities don't. No existing test expectations change.Tests
EagerImportTagTest, with fixturesmacro-and-set-reading-parent-var.jinjaandmacro-and-set-calling-parent-macro.jinja:itPreservesParentVariableReadByDeferredImportWithMacroanditPreservesParentMacroCalledByDeferredImportWithMacro. Both fail onmasterand pass with this change. The second pass runs in a fresh default-mode interpreter, so nothing from the eager pass leaks in.Eager*Test,NonRevertingEagerTest,*Import*Test,DeferredTest) all pass (811 tests). The fullmvn verifypasses (2251 tests).Results
The same templates as the Broken Examples above:
16Could not resolve function 'm'[0]🤖 Generated with Claude Code